﻿using DotNetty.Buffers;
using DotNetty.Transport.Channels;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using NetC100K;
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;

namespace NetC100KTest
{
    public class Program
    {
        public async static Task Main(string[] args)
        {
            try
            {
                var host = new HostBuilder()
                    .ConfigureAppConfiguration((configHost) =>
                    {
                        configHost.AddJsonFile("appsettings.json");
                    })
                    .ConfigureLogging((hostContext, configLogging) =>
                    {
                        configLogging.AddLog4Net();
                        configLogging.SetMinimumLevel(LogLevel.Information);
                        //configLogging.AddConsole((config) =>
                        //{
                        //    config.IncludeScopes = true;
                        //    config.Format = ConsoleLoggerFormat.Systemd;
                        //    config.TimestampFormat = "yyyy-MM-dd HH:mm:ss:fff";
                        //});
                    })
                    .ConfigureServices((hostContext, services) =>
                    {
                        services.AddSingleton<SessionPool>();
                        services.AddHostedService<HostedService>();
                        services.AddHostedService<HeartbeatHostedService>();
                    })
                    .UseConsoleLifetime()
                    .Build();
                await host.StartAsync();

                await host.WaitForShutdownAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace + "，错误：" + ex.Message);
                Console.ReadLine();
            }
        }
    }
}
